package com.blackfish.history;

import com.blackfish.common.model.Admin;
import com.blackfish.common.model.AdminHistory;
import com.blackfish.common.model.User;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import java.util.Date;
import java.util.List;

public class HistoryService {
    private AdminHistory dao = new AdminHistory().dao();

    public boolean add(String dbName,String content,User user){
        Date date = new Date();
        return new AdminHistory().set("content",content).set("user_id",user.getId()).set("db_name",dbName).set("time",date).save();
    }

    public boolean add(String dbName,String content,Admin user){
        Date date = new Date();
        return new AdminHistory().set("content",content).set("user_id",user.getId()).set("db_name",dbName).set("time",date).save();
    }

    public List<Record> findAllView(){
        return Db.find("SELECT a.name as user,h.* FROM `admin_history` as h inner join admin as a on h.user_id=a.id");
    }

}
